<template>
  <div class="mainRight">
      <div class="mainRightNav">
        <el-menu default-active="1" class="el-menu-demo" mode="horizontal">
            <el-menu-item index="1" @click="details1">热门游记</el-menu-item>
            <el-menu-item index="2" @click="details2">最新发表</el-menu-item>
            <el-button icon="el-icon-edit" class="btn11" @click="write()">写游记</el-button>
        </el-menu>
      </div>
    <div class="cardmain" v-loading="loading" element-loading-text="拼命加载中">
    <router-link v-for="(item,i) of detailss" :key="i" @click="details()" :to="`community?mid=${item.mid}`" target="_blank">
    <div class="card">
        <div class="img">
            <el-image :src="item.image"   lazy></el-image>
        </div>
        <div class="text">
            <div class="title">
                <span>{{item.title}}</span>
                <!-- <el-button type="warning" plain>顶</el-button> -->
            </div>

            <div class="detail">
                <span>{{item.lable}}</span>
            </div>
            <div class="zuozhe">
                <span>{{item.address}}</span>
                <img :src="item.authorImg" alt="" class="zztx" >
                <span class="zzname">{{item.author}}</span>
                <span class="read">{{item.browse}}</span>
                <div class="end">
                    <span class="zan">{{item.zan}}</span>
                    <el-button plain class="btn">顶</el-button>
                </div>   
            </div>
            
        </div>
    </div>
    </router-link>
    <kong v-show="hidd">
        <span>网络异常，请稍后再试</span>
    </kong>

    </div>
    <div class="mainRightPage">
        <span class="spanpage">共{{pages}}页 / {{number}}条</span>
        <el-button size="mini" class="btnp" @click="up">上一页</el-button>
        <el-button size="mini" class="btnp" disabled>{{mid}} / {{pages}}</el-button>
        <!-- <span>{{mid}} / {{pages}}</span> -->
        <el-button size="mini" class="btnp" @click="down">下一页</el-button>
    </div>
  </div>
</template>

<script>
import kong from '../../../commonality/kong.vue'
export default {
    name: "card",
    data(){
        return{
            loading:true,
            mid:1,
            detailss:'',
            pages:"",
            number:"",
            hidd:false
        }
    },
    components:{
        kong
    },
    methods:{
        open(){
            this.$message({
            message: '网络异常，请稍后再试',
            type: 'warning',
            offset:100
            });
        },
        timer(){
            setTimeout(()=>{
              if(this.loading){
                this.open()
                this.loading=false
              }else{
                  return
              }
            },5000)
        },
        http(url,page,x,y){
            this.loading=true
            this.timer()
            this.$http.get(`/${url}?mid=${page}`).then(result=>{
                // console.log(result.data)
                this.pages=result.data.pages
                this.number=result.data.num[0].num
                this.detailss=result.data.data
                window.scrollTo(x,y)
                this.loading=false
            }).catch(err=>{
                this.hidd = true
            })
        },
        details1(){
            this.mid=1
            this.http("community",this.mid,600,600)
        },
        details2(){
            this.mid=1
            this.http("communityNew",this.mid,600,600)
        },
        up(){
            if(this.mid<=1){
                return
            }else{
               this.http("community",--this.mid,0,0)
            }
        },
        down(){
            if(this.mid>=9){
                return
            }else{
            this.http("community",++this.mid,0,0)}
        },
        write(){
             this.$message({
                type:'warning',
                message:'敬请期待！'
            })
        }
    },
    mounted(){
        this.http("community",this.mid,0,0)
    }
}
</script>


<style scoped>
.el-menu--horizontal>.el-menu-item{
    font-size: 20px !important;
    color: black;
}
.el-menu--horizontal .el-menu-item:not(.is-disabled):focus, .el-menu--horizontal .el-menu-item:not(.is-disabled):hover{
    color: #41c1ec;
}
.btn11{
    margin-left: 460px;
    margin-top: 15px;
    height: 35px;
    line-height: 0px;
    color: white;
    background-color: #41c1ec;;
}
.cardmain{
    margin-top: 30px;
}
.card:hover{
    box-shadow: 0 0 10px 5px  rgb(236, 236, 236);
}
.card:hover .title{
color: #41c1ec;
}
.mainRight a{
    text-decoration: none;
}
.card{
    margin: 0 auto;
    margin-bottom: 10px;
    width: 800px;
    height: 200px;
    border: 1px solid rgb(230, 228, 228) ;
    background-color: white;
    box-sizing: border-box;
    padding-top: 15px;
    padding-left: 15px;
    border-radius: 5px;
    display: flex;
    box-sizing: border-box;
}
.img{
    width: 250px;
    overflow: hidden;
    height: 170px;
    overflow: hidden;
}
.img img{
    width: 300px;
}
.text{
    width: 420px;
    margin-left: 20px;
}
.title{
    white-space:nowrap;
    text-overflow:ellipsis;
    width: 100%;
    font-size: 23px;
    line-height: 23px;
    color: #666;
    height: 23px;
    overflow: hidden;
}
.detail{
    margin-top: 13px;
    font-size: 17px;
    width: 500px;
    height: 87px;
    overflow: hidden;
    display:-webkit-box;
    -webkit-box-orient:vertical;
    -webkit-line-clamp:4;
    text-overflow:ellipsis;
    color: #999999;
}
.zuozhe{
    margin-top: 15px;
    font-size: 15px;
    width: 500px;
}
.zuozhe span:nth-child(1){
    margin-left: 5px;
    color: #808080;
}
.zuoz{
    margin-left: 15px;
}
.zztx{
    width: 23px;
    border-radius: 20px;
    vertical-align: middle;
    margin-left: 5px;
}
.zzname{
    margin-left: 3px;
    color: #41c1ec;
}
.read{
    margin-left: 20px;
    font-weight: 550;
    color: rgb(161, 161, 161);
}
.end{
    float: right;
    margin-right: 15px;
    margin-top: -5px;
}
.zan{
    color: #41c1ec !important;
}
.btn{
    height: 30px;
    line-height: 5px;
    background-color:  #41c1ec !important;
    color: white;
    text-align: center;
}
.mainRightPage{
    width: 60%;
    height: 40px;
    margin-left: 420px;
    margin-bottom: 15px;
}
.mainRightPage span{
    font-size: 15px;
    color: #808080;
    line-height: 30px;
    margin-left: 15px;
    margin-right: 10px;
}
.spanpage{
    font-size: 12px;
    color: #808080;
    line-height: 40px;
}
.btnp{
    margin-left: 10px;
}
</style>